package com.hnevc.mallserver3.controller;

import com.hnevc.mallserver3.common.ResponseResult;
import com.hnevc.mallserver3.entity.GoodsType;
import com.hnevc.mallserver3.service.GoodsTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/goodsType")
@Api(tags = "商品类别信息接口")
public class GoodsTypeController {

    @Autowired
    private GoodsTypeService goodsTypeService;

    @PostMapping("/add")
    @ApiOperation(value = "addGoodsType", notes = "添加商品类别信息")

    public ResponseResult addGoodsType(@RequestBody GoodsType goodsType) {
        goodsTypeService.save(goodsType);
        return ResponseResult.success(goodsType);
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "getGoodsTypeById", notes = "根据ID获取商品类别")

    public ResponseResult getGoodsTypeById(@PathVariable Long id) {
        GoodsType goodsType = goodsTypeService.getById(id);
        return ResponseResult.success(goodsType);
    }

    @GetMapping("/list")
    @ApiOperation(value = "listGoodsTypes", notes = "获取所有商品类别信息")
    public ResponseResult listGoodsTypees() {
        List<GoodsType> goodsTypes = goodsTypeService.list();
        return ResponseResult.success(goodsTypes);
    }

    @PutMapping("/update")
    @ApiOperation(value = "updateGoodsType", notes = "更新商品类别信息")

    public ResponseResult updateGoodsType(@RequestBody GoodsType goodsType) {
        goodsTypeService.updateById(goodsType);
        return ResponseResult.success(null);
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "deleteGoodsType", notes = "删除商品类别信息根据ID")

    public ResponseResult deleteGoodsType(@PathVariable Long id) {
        goodsTypeService.removeById(id);
        return ResponseResult.success(null);
    }
}